
local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name);
local EventList = ClientOHOH.load.EventList();

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.player=parent

	self.DataBase=self.player:GetComponent(ClientOHOH.load.Client_PlayerDataComponent())

    -- self.player.UserDataEvent:Connect(function(data)
	-- 	-- ClientOHOH:PrintTable(data)
    -- end);

	--存档Roll出来的部件
	self.player.RollResultEvent:Connect(function(data)
		for _,id in pairs(data) do
			self.DataBase:SimulateModifyDataAdd({"car","had",id},1)
		end

	end)

end;



function M.IsSendCdOver(self)
	if not self.lastCdTime then
		self.lastCdTime=os.clock()
		return  true
	end
	if os.clock()-self.lastCdTime>0.5 then
		self.lastCdTime=os.clock()
		return  true
	end
	return  false
end

function M.dtor(self)
	M.super.dtor(self);
end;


function M.Roll(self,data)
	self.player.RollResultEvent:Action(data)
end

M:RegistEvent(EventList.one_roll,M.Roll)

--------------------------------------对外接口----------------------------------------------------
-- 开关自动Roll->参数:isOpen:true(自动)，false(手动)
function M.CloseOrOpenAuto(self,isOpen)
	if self:IsSendCdOver() then
		self:Fire(EventList.setIsAuto_roll,isOpen)
	end
end


--开启一次Roll
function M.OneRoll(self)
	if self.DataBase:GetData("rollSetting").isAuto==0 then
		self:Fire(EventList.roll_one)
	end
end

return M
